package com.scedu;

import com.github.pagehelper.PageHelper;
import com.scedu.dao.StudentDao;
import com.scedu.entity.Student;
import com.scedu.utils.MybatisUtil;
import com.scedu.vo.QueryParam;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class App {
    public static void main(String[] args) {

        SqlSession sqlSession = MybatisUtil.getSqlSession();

        StudentDao mapper = sqlSession.getMapper(StudentDao.class);
        System.out.println("动态sql语句if查询");
        Student sqlStudent=new Student();
        sqlStudent.setName("张三");
        sqlStudent.setAge(11);
        List<Student> studentList = mapper.selectStudentIf(sqlStudent);
        for (Student student : studentList) {
            System.out.println(student);
        }
        System.out.println("动态sql语句where查询");
        sqlStudent.setName("");
        List<Student> studentList1 = mapper.selectStudentWhere(sqlStudent);
        for (Student student : studentList1) {
            System.out.println(student);
        }
        System.out.println("动态sql语句foreach查询");
        List<Integer> list = new ArrayList<>();
        list.add(1001);
        list.add(1002);
        list.add(1003);
        List<Student> studentList2 = mapper.selectFor(list);
        for (Student student : studentList2) {
            System.out.println(student);
        }
        System.out.println("动态sql语句foreach查询2");
        List<Student> listStudent = new ArrayList<>();
        Student student1 = new Student(1001, "zs", "zs@qq.com", 11);
        Student student2 = new Student(1002, "lisi", "lisi@qq.com", 12);
        listStudent.add(student1);
        listStudent.add(student2);

        List<Student> studentList3 = mapper.selectForStudent(listStudent);
        for (Student student : studentList3) {
            System.out.println(student);
        }
        System.out.println("===========分页插件============");
        // 获取第 1 页，3 条内容
        PageHelper.startPage(1,3);
        List<Student> studentListPage = mapper.selectAllStudent();
        studentListPage.forEach( stu -> System.out.println(stu));

    }
    @Test
    public void testSelect() throws IOException {
        SqlSession sqlSession = MybatisUtil.getSqlSession();

        StudentDao mapper = sqlSession.getMapper(StudentDao.class);
        // 获取第 1 页，3 条内容
        PageHelper.startPage(1,3);
        List<Student> studentList = mapper.selectAllStudent();
        studentList.forEach( stu -> System.out.println(stu));
    }
}
